package dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import utiles.Conecta;
import dto.leerRankingADTO;

public class leerRankingADAO {

public List getALLRankingA(String codigoConcurso, String ano, String mes, String path, String fileName, String tipo) throws SQLException, IOException{
		
		Conecta connDao = new Conecta();
		Connection conn = connDao.ObtieneConexion();	
		List listLeerRanka = new ArrayList();
		PreparedStatement stmt = null; 
        ResultSet rs=null; 
		try{
			String sql = "select * from  " + Conecta.schema + ".CC_CORREDORESPERIODO where CODIGOCONCURSO=? and ANO=? and MES=? and  CODIGOCATEGORIA = '"+ tipo +"' AND POSICIONRANKING > 0 ORDER BY POSICIONRANKING  ";   
            
            stmt=conn.prepareStatement(sql);  
            rs=stmt.executeQuery();
			
			
			while (rs.next()) {
				
				leerRankingADTO BuscaDTO = new leerRankingADTO();				
				BuscaDTO.setCodigoConcurso(rs.getString(1));
				BuscaDTO.setRutCorredor(rs.getString(2));
				BuscaDTO.setCodigoCategoria(rs.getString(3));
				BuscaDTO.setPrimaPartida(rs.getString(4));
				BuscaDTO.setPrimaVenta(rs.getString(5));
				BuscaDTO.setCrecimiento(rs.getString(6));
				BuscaDTO.setPuntaje(rs.getString(7));
				BuscaDTO.setNombreBT1(rs.getString(8));
				BuscaDTO.setValorBT1(rs.getString(9));
				BuscaDTO.setCrecimientoAcumulado(rs.getString(10));
				BuscaDTO.setPuntajeAcumulado(rs.getString(11));
				BuscaDTO.setPrimaVendidaFechu(rs.getString(12));
				BuscaDTO.setPosicionRanking(rs.getString(13));
				BuscaDTO.setCrecimientoAcumuladoFusion(rs.getString(14));
				BuscaDTO.setPuntajeAcumuladoFusion(rs.getString(15));
				BuscaDTO.setNombreCorredor(rs.getString(16));
				BuscaDTO.setNombreCategoria(rs.getString(17));
				BuscaDTO.setNombreCorredorLider(rs.getString(18));
				
				System.out.println(rs.getString(1));
				System.out.println(rs.getString(2));
				System.out.println(rs.getString(3));
				System.out.println(rs.getString(4));
				System.out.println(rs.getString(5));
				System.out.println(rs.getString(6));
				System.out.println(rs.getString(7));
				System.out.println(rs.getString(8));
				System.out.println(rs.getString(9));
				System.out.println(rs.getString(10));
				System.out.println(rs.getString(11));
				System.out.println(rs.getString(12));
				System.out.println(rs.getString(13));
				System.out.println(rs.getString(14));
				System.out.println(rs.getString(15));
				System.out.println(rs.getString(16));
				System.out.println(rs.getString(17));
				System.out.println(rs.getString(18));
				
				
				listLeerRanka.add(BuscaDTO);				
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			
			System.out.println(ex.getMessage());
		} finally {
			
			connDao.desconecta(conn);
		}	
	return listLeerRanka;
}
	public static void main(String[] args) {
	
		leerRankingADAO carga = new leerRankingADAO();
		try {
			carga.getALLRankingA("CONCURSO2011","2011","7","","","A");
		} catch (SQLException e) {		
			
			
			e.printStackTrace();
		} catch (IOException e) {
		
			e.printStackTrace();
		}
	}
}
